home *** CD-ROM | disk | FTP | other *** search
- Path: kbad.eglin.af.mil!rpi!not-for-mail
- From: floydb1@lib104.its.rpi.edu (Barry B Floyd)
- Newsgroups: comp.lang.c++
- Subject: Re: String operator+ and memory leakage.
- Date: 19 Apr 1996 12:27:42 -0400
- Organization: Rensselaer Polytechnic Institute, Troy, NY.
- Message-ID: <4l8etu$vu@lib104.its.rpi.edu>
- References: <4l5fok$feo@utopia.hacktic.nl>
- NNTP-Posting-Host: lib104.its.rpi.edu
- X-newsreader: xrn 7.04-beta-11
-
-
- ------------------------------------------------------------------------
- in file:
- ~gnu/libg++/2.7.0a/distrib/src/libg++/src/String.h
-
-
- inline String operator+ (const String& x, const char* y)
- { String r ; cat(x, y, r) ; return r ; }
-
- inline String operator+ (const char* x, const String& y)
- { String r ; cat(x, y, r) ; return r ; }
-
-
-
- inline String& String::operator = (const String& y)
- { rep = Scopy(rep, y.rep) ;
- return *this ; }
-
- inline String& String::operator= (const char* t)
- { rep = Salloc(rep, t, -1, -1) ;
- return *this ; }
-
-
-
- inline static void scopy(const char* from, char* to)
- { if (from != 0) while((*to++ = *from++) != 0) ; }
-
-
- struct StrRep // internal String representations
- {
- unsigned short len ; // string length
- unsigned short sz ; // allocated space
- char s[1] ; // the string starts here (at
- // least 1 char for trailing
- // null) allocated & expanded
- // via non-public fcts
- } ;
-
- ------------------------------------------------------------------------
- in file:
- ~gnu/libg++/2.7.0a/distrib/src/libg++/src/String.cc
-
- StrRep *Salloc(StrRep* old, const char* src, int srclen, int newlen)
- { // allocate, copying src if nonull
-
- if (old == &_nilStrRep) old = 0 ;
- if (srclen < 0) srclen = slen(src) ;
- if (newlen < srclen) newlen = srclen ;
-
- StrRep *rep ;
-
- if (old == 0 || newlen > old->sz)
- rep = Snew(newlen) ;
- else
- rep = old ;
-
- rep->len = newlen ;
- ncopy0(src, rep->s, srclen) ;
-
- if (old != rep && old != 0)
- delete old ;
-
- return rep ;
- }
-
- --
- +--------------------------------------------------------------------+
- | Barry B. Floyd \\\ floydb1@rpi.edu |
- | RPI Alum. '84 '87 '88 \\\ |
- +--------------------------------------------------------------------+
-